<template>
  <div class=container>
    <viewer
        ref="myViewer"
        :docs="docs"
        :key="newkey"
        :multiple="multiple"
        @savePic="savePic"
        @saveCamera="saveCamera"
    >
      <slot>
        <div class="slot">
          <h5>自定义插槽位置</h5>
          <el-button type="primary" size="small" @click="reloadModel">重启模型</el-button>
          <el-button type="primary" size="small" @click="savePicBtn">保存截图</el-button>
          <el-button type="primary" size="small" @click="saveCameraBtn">保存视角</el-button>
          <el-button type="primary" size="small" @click="redCameraBtn">读取视角</el-button>
        </div>
      </slot>
    </viewer>
    <el-dialog title="保存截图" :visible.sync="dialogTableVisible">
      <img :src="base64Src" alt="">
    </el-dialog>
  </div>
</template>

<script>

import viewer from '../../src/components/viewer'

export default {
  components: {
    viewer
  },
  data() {
    return {
      newkey: null, // 模型环境变量
      docs: [],
      multiple: false,
      dialogTableVisible: false,
      base64Src: '',
    };
  },
  mounted() {
    this.newkey = Math.random();
    this.docs = [
      {
        "name": 1,
        "type": 'dwg',
        "folder": "/output",
        "path": "http://wlui.oss-cn-beijing.aliyuncs.com/bimdata/demo1/0.svf",
      }
    ]
  },
  methods: {
    // 重启模型
    reloadModel() {
      this.$refs.myViewer.reloadModel();
      this.$message({
        message: '重启已模型',
        type: 'success'
      });
    },
    // 保存截图
    savePicBtn() {
      this.$refs.myViewer.savePic();
    },
    savePic(base64) {
      this.base64Src = base64;
      this.dialogTableVisible = true;
    },
    // 保存视角
    saveCameraBtn() {
      this.$refs.myViewer.saveCamera();
    },
    saveCamera(camData) {
      this.camData = camData;
      this.$message({
        message: '视角已保存',
        type: 'success'
      });
    },
    // 读取视角
    redCameraBtn() {
      this.$refs.myViewer.readCamera(this.camData);
    },
  }
}
</script>

<style scoped>
.slot {
  position: absolute;
  width: 100px;
  z-index: 9999;
  left: 10px
}
.slot /deep/ button {
  margin-bottom: 10px;
  float: left;
  margin-left: 0;
}
</style>
